﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using App.Core.Extensions;
using App.Data;
using System.Data;
using App.Core.DB;

public partial class Pages_Private_ViewBookings : BasePage
{
    private int _EventID = 0;

    protected void Page_Load(object sender, EventArgs e)
    {
        BindPageInfo();
        if (!IsPostBack)
        {
            BindEventsList(1);
        }
    }
    protected void BindPageInfo()
    {
        Page.Title = WebUtil.GetPageTitle(h4Heading.InnerHtml);
        _EventID = WebUtil.GetQueryStringInInt(AppConstants.QueryString.ID);
    }
    protected void BindEventsList(int pageNumber)
    {
        UtilityDAO dao = new UtilityDAO();
        int totalRecord = 0;
        App.Data.DbParameter[] parameters = new[] { new App.Data.DbParameter("@EventID", _EventID) };
        DataSet ds = dao.GetPagedData(AppSQL.GET_BOOKINGS_BY_EVENT_ID, parameters, pageNumber, ConfigReader.EventBookingListSize, out totalRecord);
        ucEventBookingList.DataSource = ds.Tables[0];        
        ucEventBookingList.NoRecordMessgae = "No Booking wass submitted for this Event.";
        ucEventBookingList.DataBind();        
       

        ///Bind the Pager Control
        ucEventBookingListPager.TotalRecord = totalRecord;
        ucEventBookingListPager.PageNo = pageNumber;
        ucEventBookingListPager.PageSize = ConfigReader.EventBookingListSize;
        ucEventBookingListPager.TotalRecordMessage = "Total {0} Booking(s) Found.";
        ucEventBookingListPager.DataBind();
    }
    protected String GetFormattedData(object data)
    {
        if (data.GetType() == typeof(String))
        {
            String text = NullHandler.GetString(data);
            if (text.WordCount() > 30)
                text = text.GetWords(30);
            return WebUtil.FormatText(text);
        }
        else
            return WebUtil.FormatData(data);
    }
    protected void ucEventBookingListPager_PageIndexChanged(object sender, PagerEventArgs e)
    {
        BindEventsList(e.PageIndex);
    }
}